import React, { Component } from 'react'
import {Route,Switch ,Redirect} from "react-router-dom";

// 路由页面
import index from "../views/index";
import login from "../views/login";
import register from "../views/register";
import list from "../views/list";
import details from "../views/details";
import shoppingCar from "../views/shoppingCar";
import myself from "../views/myself";
import orderForGoods from "../views/order_for_goods";
import paySuccess from "../views/paySuccess";
import orderDetails from "../views/order_details";
import updataPassword from "../views/updata_password"
import no from "../views/no"
import Admin from "../views/admin"

export default class Router extends Component {
    render() {
        return (
            <div>
                {/* 设置路由导航 普通用户进入*/}
                <Switch>
                <Route path="/index" component={index}/>
                <Route path="/login" component={login}/>
                <Route path="/register" component={register}/>
                <Route path="/list" component={list}/>
                <Route path="/details/:id" component={details}/>
                <Route path="/shoppingCar" component={shoppingCar}/>
                <Route path="/myself" component={myself}/>
                <Route path="/orderForGoods" component={orderForGoods}/>
                <Route path="/paySuccess" component={paySuccess}/>
                <Route path="/orderDetails" component={orderDetails} />
                <Route path="/updataPassword" component={updataPassword} />
                {/* <Route path="/orderdetails" component={}/> */}
                {/* 管理员用户进入 路由守卫 */}
                <Route path="/admin" render={(props)=>{
                    if(sessionStorage.getItem("userIdcard") == 1){
                        return <Admin {...props}></Admin>
                        }else if(sessionStorage.getItem("userIdcard") == 0){
                            return <Redirect to="/index" />
                        }else{
                            return <Redirect to="/index" />
                        }
                    }     }  />
                <Redirect from="/" to="index" exact/>
                <Route component={no}/> 

                </Switch>
            </div>
        )
    }
}
